﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoShopping.Model;

namespace GoShopping.BLL.SysInfo
{
    public class Log_EmailSendListBean
    {
        /// <summary>
        /// 增加一条Log_EmailSendList
        /// </summary>
        /// <param name="log"></param>
        public void Add(Log_EmailSendList log)
        {
            Databases.DBGoShopping.Insert(
                GoShoppingNBear.Log_EmailSendList).AddColumn(
                GoShoppingNBear.Log_EmailSendList.CreateDate, log.CreateDate).AddColumn(
                GoShoppingNBear.Log_EmailSendList.EmailContent, log.EmailContent).AddColumn(
                GoShoppingNBear.Log_EmailSendList.EmailTemplateID, log.EmailTemplateID).AddColumn(
                GoShoppingNBear.Log_EmailSendList.EmailTemplateName, log.EmailTemplateName).AddColumn(
                GoShoppingNBear.Log_EmailSendList.FromEmail, log.FromEmail).AddColumn(
                GoShoppingNBear.Log_EmailSendList.IsSended, false).AddColumn(
                GoShoppingNBear.Log_EmailSendList.SendAdminName, log.SendAdminName).AddColumn(
                GoShoppingNBear.Log_EmailSendList.SendedDate, log.SendedDate).AddColumn(
                GoShoppingNBear.Log_EmailSendList.ToUserEmail, log.ToUserEmail).AddColumn(
                GoShoppingNBear.Log_EmailSendList.ToUserID, log.ToUserID).AddColumn(
                GoShoppingNBear.Log_EmailSendList.EmailSubject, log.EmailSubject).AddColumn(
                GoShoppingNBear.Log_EmailSendList.ToUserName, log.ToUserName).Execute();
        }

        /// <summary>
        /// 更新发送邮件历史记录的 邮件发送成功状态
        /// </summary>
        /// <param name="logEmailID"></param>
        public void UpdateOneLogMailSendStatue(int logEmailID)
        {
            Databases.DBGoShopping.Update(GoShoppingNBear.Log_EmailSendList).AddColumn(
                GoShoppingNBear.Log_EmailSendList.IsSended, true.ToString()).Where(
                GoShoppingNBear.Log_EmailSendList.ID == logEmailID).Execute();
        }

        /// <summary>
        /// 查询邮件发送记录
        /// </summary>
        /// <param name="conditionStr">传入空字符串则表示查找全部</param>
        /// <returns></returns>
        public IList<Log_EmailSendList> GetLogMail(string conditionStr)
        {
            string sql = "SELECT * FROM " + GoShoppingNBear.Log_EmailSendList.___GetTableName() +
                " WHERE 1=1 ";
            return Databases.DBGoShopping.CustomSql(sql).ToList<Log_EmailSendList>();
        }
    }
}
